<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>9.24 课后作业</title>
</head>

<body>
    <script>
        //1.slice
        let arr = ["JavaScript", "C语言", "大学数学", "Web前端"]
        console.log("原数组： ", arr)
        console.log("arr.slice(1,3) 执行结果：", arr.slice(1, 3))
        //当 第二个参数 超过数组长度时，slice 方法会自动提取到数组末尾
        console.log("arr.slice(1,4) 执行结果：", arr.slice(1, 4))
        console.log("arr.slice(2) 执行结果：", arr.slice(2))

        console.log("\n")

        //2.reduce
        let arr1 = [{ name: "笔记本", price: 5999, count: 2 },
        { name: "鼠标", price: 199, count: 5 },
        { name: "键盘", price: 499, count: 3 }]
        console.log("原数组： ", arr1)
        console.log("商品总金额： ", arr1.reduce((sum, obj) => sum + (obj.price * obj.count), 0))

        console.log("\n")

        //3.for循环遍历
        let arr2 = [{ name: "张三", score: 85 },
        { name: "李四", score: 92 },
        { name: "王五", score: 78 },
        { name: "赵六", score: 95 }]
        console.log("原数组： ", arr1)
        console.log("for-of循环")
        for (i of arr2) {
            console.log(i.name + "的成绩:" + i.score + "分")
        }
        console.log("for-in循环")
        for (i in arr2) {
            console.log(arr2[i].name + "的成绩:" + arr2[i].score + "分")
        }

        console.log("\n")

        //4.对象
        let arr3 = {
            name: "陈小明",
            age: 28,
            address: {
                city: "北京",
                district: "海淀区"
            },
            hobbies: ["篮球", "阅读", "编程"]
        }
        console.log("原数组： ", arr3)
        console.log("居住地： ", arr3.address)
        console.log("爱好： ", arr3.hobbies)



    </script>
</body>

</html>